package cn.edu.zjut.mina.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.zjut.mina.service.IClientUpdateService;

@Controller
@RestController
@RequestMapping("/update")
public class ClientUpdateAction {
	
	@Qualifier("clientUpdateService")
	@Autowired
	private IClientUpdateService clientUpdateService;
	
	
	/**
	 * apk文件下载
	 * @param cateogry 文件名
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/list/{cateogry}", method = RequestMethod.GET)
	public void clientGetResList(@CookieValue(value = "userinfo", defaultValue = "") String userCookie,
			@PathVariable("cateogry") String cateogry,
            HttpServletRequest request,
            HttpServletResponse response){
		System.out.println("收到请求" + "clientGetResList");
		clientUpdateService.clientGetResList(userCookie, cateogry, request,response);
	}
	
	@RequestMapping(value = "/res/{cateogry:.*}", method = RequestMethod.GET)
	public void clientGetRes(@RequestParam("path")String path,@CookieValue(value = "userinfo", defaultValue = "") String userCookie,
			@PathVariable("cateogry") String cateogry,
            HttpServletRequest request,
            HttpServletResponse response){
		System.out.println("收到请求" + "clientGetRes" + path + " " + cateogry);
		clientUpdateService.clientGetRes(userCookie, path, cateogry, request,response);
	}

}
